// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        id: 0,
        value: cc.Label,
        color: cc.Color,
        valueStr: "",
        selected: false,
        selectable: false
    },

    init: function (item) {
        this.id = item.id
        this.valueStr = this.value.string = item.filledValue == "0" ? "" : item.filledValue + ""
        this.setSelected(false)
        if (this.valueStr == "") {
            this.selectable = true
        }
    },
    updateValue: function (value) {
        this.valueStr = this.value.string = (value == 0 || value == "0") ? "" : value + ""
        return this
    },
    setSelected: function (select) {
        this.node.color = select ? cc.Color.GRAY : cc.Color.WHITE
        this.selected = select
        return this
    },
    setConflict: function (conflict) {
        this.node.color = conflict ? cc.Color.YELLOW : cc.Color.WHITE
        if (!conflict && this.selected) {
            this.setSelected(this.selected)
        }
        return this
    }
});
